package com.qf.boot2202;

import com.qf.boot2202.config.AnotherConfig;
import com.qf.boot2202.config.Car;
import com.qf.boot2202.config.MyCarProperty;
import com.qf.boot2202.config.UserProperty;
import com.qf.boot2202.entity.User;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.ImportResource;

import java.io.UnsupportedEncodingException;

@SpringBootApplication
@Import({AnotherConfig.class})  // 导入配置类
@ImportResource(locations = "classpath*:spring-context.xml")
@EnableConfigurationProperties({Car.class,UserProperty.class})
public class Boot2202Application {

    public static void main(String[] args) throws UnsupportedEncodingException {
        // 获取IOC容器对象
        final ConfigurableApplicationContext context = SpringApplication.run(Boot2202Application.class, args);

//        final User userA = (User) context.getBean("user01");
//
//        final User userB = context.getBean("user01", User.class);
//
//        System.out.println(userA == userB);

//
//        final User user03 = context.getBean("user03", User.class);
//        System.out.println(user03);

//        final User user04 = context.getBean("user04", User.class);
//        System.out.println(user04);

//        System.out.println(context.getBean("user05", User.class));


//        final MyCarProperty myCarProperty = context.getBean("myCarProperty", MyCarProperty.class);
//        System.out.println(myCarProperty);


//        final Car car = context.getBean(Car.class);
//        System.out.println(car);
//        final String brand = car.getBrand();
//        final byte[] bytes = brand.getBytes("iso8859-1");
//
//        System.out.println(new String(bytes, "utf-8"));


        final UserProperty bean = context.getBean(UserProperty.class);
        System.out.println(bean);


    }


    @Bean
    public User user05(){
        return new User(500, "zero");
    }

}
